﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Empires.PL.PageHandler;
using Empires.PL.PageBuilder;
using Empires.PL.Web.Models;
using Empires.PL.ServiceClient;
using System.Text.RegularExpressions;
using Empires.CRL.Tools;
using Empires.CRL.DataContract;

namespace Empires.PL.Web.Controllers
{
     [HandlerError]
    public class CompanyController : Controller
    {
         //
         // GET: /Company/
         //[OutputCache(VaryByParam="id", Duration=300)]
         public ActionResult Index(string id)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("index.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
         //[OutputCache(VaryByParam = "id", Duration = 300)]
         public ActionResult About(string id)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("about.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
        //[OutputCache(VaryByParam = "id;type;subject;page;size", Duration = 300)]
         public ActionResult News(string id, string type = "", string subject = "", int page = 0, int size = 0)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("news.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
         public ActionResult NewsDetail(string id, string nid)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("newsdetail.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
         public ActionResult Notice(string id, int nid)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("notice.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
         //[OutputCache(VaryByParam = "id;type;subject;page;size", Duration = 300)]
         public ActionResult Product(string id, string type = "", string subject = "", string page = "", string size = "")
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("product.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
        //[OutputCache(VaryByParam = "id;pid", Duration = 300)]
         public ActionResult ProductDetail(string id, string pid)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("productdetail.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }

         public ActionResult Business(string id, int item = -1, int type = 1)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("business.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
        //[OutputCache(VaryByParam = "id", Duration = 300)]
         public ActionResult ServiceItem(string id)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("serviceitem.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
         //[OutputCache(VaryByParam = "id", Duration = 300)]
         public ActionResult Download(string id)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("download.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
         //[OutputCache(VaryByParam = "id;from;fid", Duration = 300)]
         public void DownloadFile(string id, string from, int fid)
         {
             string filepath = ServiceClient.CompanyDownloadServiceClient.GetDownloadFileURL(fid, id);
             if (String.IsNullOrEmpty(filepath))
             {
                 Response.Redirect(from);
             }
             bool issuccess = CRL.Tools.FileDownLoad.
                 DownLoadFile(System.Web.HttpContext.Current.Request, System.Web.HttpContext.Current.Response, Server.MapPath(filepath), 50 * 1024);
             if (!issuccess)
             {
                 Response.Write("文件下载失败");
             }
             System.Web.HttpContext.Current.Response.End();
         }
         //[OutputCache(VaryByParam = "id", Duration = 300)]
         public ActionResult Blog(string id)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("blog.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
         //[OutputCache(VaryByParam = "id;article", Duration = 300)]
         public ActionResult Article(string id, int article)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             var pack = Commander.Analysis("article.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
         //[OutputCache(VaryByParam = "id", Duration = 300)]
         public ActionResult Online(string id)
         {
             var pack = Commander.Analysis("online.html", id);
             ViewData["head"] = pack.Head;
             ViewData["body"] = pack.Body;
             ViewData["copName"] = id;
             return View();
         }
         [HttpPost]
         public ActionResult Online(string id, OnlineModels model)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             if (!String.IsNullOrEmpty(model.Content))
             {
                 if (model.PostMode == "0")
                 {
                     CompanyOnlineServiceClient.PostOnlineConsultation(id, model.Author, model.Content);
                 }
                 else if (model.PostMode == "1")
                 {
                     CompanyOnlineServiceClient.PostOnlineReply(id, model.Mid, model.Author, model.Content, model.Phone);
                 }
             }
             return Redirect("/Online");
         }
         public ActionResult PostSuccess(string id, string redirect)
         {
             if (string.IsNullOrEmpty(id))
             {
                 return Redirect("/home/index");
             }
             return View();
         }

          /*后台***********************/
         [CompanyAuth()]
         public ActionResult Console(string id)
         {
             var pack = Empires.PL.ServiceClient.CompanyNoticeServiceClient.GetNoticeList(id, 0, 0, 8);
             ViewData["Notices"] = pack;
             return View();
         }
         public ActionResult SignIn(string id)
         {
             if (HttpContext.User.Identity.IsAuthenticated)
             {
                 var username = HttpContext.User.Identity.Name;
                 if (username == Empires.PL.ServiceClient.CompanyBaseServiceClient.GetMasterName(id))
                 {
                     return RedirectToAction("Console");
                 }
                 else
                 {
                     System.Web.Security.FormsAuthentication.SignOut();
                     return Redirect("/SignIn");
                 }
             }
             var pack = Empires.PL.ServiceClient.CompanySettingServiceClient.GetLogoInfo(id);
             if (pack.Any())
             {
                 ViewData["Logo"] = pack[0];
             }
             return View(new ConsoleSignInModels());
         }
         [HttpPost]
         public ActionResult SignIn(string id, ConsoleSignInModels model)
         {
             var pack = Empires.PL.ServiceClient.CompanySettingServiceClient.GetLogoInfo(id);
             if (pack.Any())
             {
                 ViewData["Logo"] = pack[0];
             }
             if (ModelState.IsValid)
             {
                 if (model.UserName != Empires.PL.ServiceClient.CompanyBaseServiceClient.GetMasterName(id))
                 {
                     ModelState.AddModelError("", "您没有访问带控制台的权利。");
                 }
                 else
                 {
                     var result = AppUserServiceClient.UserLogin(model.UserName, model.PassWord, false);
                     if (!result)
                     {
                         ModelState.AddModelError("", "提供的用户名或密码不正确。");
                     }
                     else
                     {
                         return RedirectToAction("Console");
                     }
                 }
             }
             return View(model);
         }
         public ActionResult SignOut(string id)
         {
             if (HttpContext.User.Identity.IsAuthenticated)
             {
                 System.Web.Security.FormsAuthentication.SignOut();
             }
             return RedirectToAction("Index");
         }
         [CompanyAuth()]
         public ActionResult BaseConfig(string id)
         {
             BaseConfigModels model = new BaseConfigModels();
             var pack = PL.ServiceClient.CompanyManagementServiceClient.CompanyManagementService(id);
             if (pack != null)
             {
                 model.ICP = pack.ICP;
                 model.Calling = pack.Calling;
                 model.EMail = pack.EMail;
                 model.KeyWord = pack.KeyWord;
                 model.Main = pack.Main;
                 model.QQ1 = pack.QQ1;
                 model.QQ2 = pack.QQ2;
                 model.Title = pack.Title;
             }
             return View(model);
         }
         [CompanyAuth()]
         [HttpPost]
         public ActionResult BaseConfig(string id, BaseConfigModels model)
         {
             if (!ModelState.IsValid)
             {
                 model.IsValid = false;
                 return View(model);
             }
             PL.ServiceClient.CompanyManagementServiceClient.UpdateBaseConfig(id, new CRL.DataContract.BaseConfigDataPack()
             {
                 Calling = model.Calling,
                 EMail = model.EMail,
                 ICP = model.ICP,
                 KeyWord = model.KeyWord,
                 Main = model.Main,
                 QQ1 = model.QQ1,
                 QQ2 = model.QQ2,
                 Title = model.Title
             });
             model.InjuectProcessSuccessMessage();
             model.IsValid = true;
             return View(model);
         }
         [CompanyAuth()]
         public ActionResult Poster(string id)
         {
             var data = PL.ServiceClient.CompanySettingServiceClient.GetScrollImgs(id, 5);
             ViewData["Data"] = data;
             return View();
         }
         [CompanyAuth()]
         public ActionResult AboutMG(string id)
         {
             AboutMGModels model = new AboutMGModels();
             var pack = CompanyAboutServiceClient.GetAboutInfo(id)[0];
             model.AboutContent = pack.EXTFIELD4;
             //model.AboutUsImg = pack.URL;
             model.Address = pack.AddRESS;
             model.Faith = pack.EXTFIELD1;
             model.Professional = pack.EXTFIELD2;
             model.Qualification = pack.EXTFIELD3;
             model.ServiceLine = pack.PHONE;
             model.ZipCode = pack.ZIPCODE;

             return View(model);
         }
         [CompanyAuth()]
         [HttpPost]
         [ValidateInput(false)]
         public ActionResult AboutMG(string id, AboutMGModels model)
         {
             Regex reg = new Regex(CommonRegexpLib.IsJPGorPNG);
             if (!ModelState.IsValid || (!String.IsNullOrEmpty(Request.Files["AboutUsImg"].FileName) && !reg.IsMatch(Request.Files["AboutUsImg"].FileName)))
             {
                 ModelState.AddModelError("", "上传图片必须为jpg或png格式");
                 model.IsValid = false;
                 return View(model);
             }
             if (PL.ServiceClient.CompanyAboutServiceClient.UpdateAboutInfo(id,
                 new CRL.DataContract.AboutDataPack()
                 {
                     AboutContent = model.AboutContent,
                     //AboutUsImg = model.AboutUsImg,
                     Address = model.Address,
                     Faith = model.Faith,
                     Professional = model.Professional,
                     Qualification = model.Qualification,
                     ServiceLine = model.ServiceLine,
                     ZipCode = model.ZipCode
                 }))
             {
                 model.InjuectProcessSuccessMessage();
                 model.IsValid = true;
             }
             return View(model);
         }
         [CompanyAuth()]
         public ActionResult NewsMG(string id, int page = 0)
         {
             NewsMGModels model = new NewsMGModels();
             var list = PL.ServiceClient.CompanyNewsServiceClient.GetNewsList(id, string.Empty, string.Empty, page, 15);
             ViewData["Data"] = list;
             return View(model);
         }
         [CompanyAuth()]
         [HttpPost]
         [ValidateInput(false)]
         public ActionResult NewsMG(string id, NewsMGModels model)
         {
             var list = PL.ServiceClient.CompanyNewsServiceClient.GetNewsList(id, string.Empty, string.Empty, 0, 15);
             ViewData["Data"] = list;
             if (!ModelState.IsValid)
             {
                 ModelState.AddModelError("", "请输入完善的信息");
                 model.IsValid = false;
                 return View(model);
             }
             int result = CompanyNewsServiceClient.AddNewsItem(id, model.Author, model.Content, model.From, model.Title);
             if (result == 1)
             {
                 model.InjuectProcessSuccessMessage();
             }
             else
             {
                 ModelState.AddModelError("", "操作失败，请稍候再试");
                 model.IsValid = false;
             }
             return View(model);
         }
         [CompanyAuth()]
         public void DeleteNewsItemMG(string id, string newsid)
         {
             int result = CompanyNewsServiceClient.DeleteNewsItem(id, newsid);
             Response.Write(result);
         }
         [CompanyAuth()]
         public ActionResult ProductMG(string id, int page = 0)
         {
             var list = PL.ServiceClient.CompanyProductServiceClient.GetProductWithList(id, string.Empty, string.Empty, page, 6);
             ViewData["Data"] = list;
             return View();
         }
         [CompanyAuth()]
         public ActionResult ProductEditMG(string id, string pid)
         {
             ProductMGModels model = new ProductMGModels();
             int _pid = 0;
             Int32.TryParse(pid, out _pid);
             var list = PL.ServiceClient.CompanyProductServiceClient.GetProductDetail(_pid);
             if (list != null && list.Any() && list[0].ID > 0)
             {
                 model.Pid = list[0].ID.ToString();
                 model.Author = list[0].AUTHOR;
                 model.Content = list[0].CONTENT;
                 model.Date = list[0].DATE;
                 model.From = list[0].FROM;
                 model.Hit = list[0].HIT.ToString();
                 model.Title = list[0].TITLE;
                 return View(model);
             }
             else
             {
                 return RedirectToAction("ProductMG");
             }
         }
         /// <summary>
         /// 删除产品
         /// </summary>
         /// <param name="id"></param>
         /// <param name="pid"></param>
         /// <returns>成功返回：1，失败返回：0</returns>
         [CompanyAuth()]
         public int ProductDeleteMG(string id, string pid)
         {
             int _pid = 0;
             if (!Int32.TryParse(pid, out _pid))
             {
                 return 0;
             }
             if (!PL.ServiceClient.CompanyProductServiceClient.ProductDelete(id, _pid))
             {
                 return 0;
             }
             return 1;
         }
         [CompanyAuth()]
         [ValidateInput(false)]
         [HttpPost]
         public ActionResult ProductEditMG(string id, ProductMGModels model)
         {
             if (!ModelState.IsValid)
             {
                 ModelState.AddModelError("", "操作失败");
                 model.IsValid = false;
                 return View(model);
             }
             if (PL.ServiceClient.CompanyProductServiceClient.ProductEdit(id,
                 new ProductDataPack()
                 {
                     ID = Int32.Parse(model.Pid),
                     Author = model.Author,
                     Content = model.Content,
                     Date = model.Date,
                     From = model.From,
                     Hit = model.Hit,
                     Title = model.Title,
                     URL = model.URL
                 }))
             {
                 model.InjuectProcessSuccessMessage();
                 model.IsValid = true;
             }
             return View(model);
         }
         [CompanyAuth()]
         public ActionResult ProductAddMG(string id)
         {
             ProductMGModels model = new ProductMGModels();
             return View(model);
         }
         [CompanyAuth()]
         [ValidateInput(false)]
         [HttpPost]
         public ActionResult ProductAddMG(string id, ProductMGModels model)
         {
             if (!ModelState.IsValid)
             {
                 ModelState.AddModelError("", "一些字段输入有误");
                 model.IsValid = false;
                 return View(model);
             }
             if (PL.ServiceClient.CompanyProductServiceClient.ProductAdd(id,
                 new ProductDataPack()
                 {
                     Author = model.Author,
                     Content = model.Content,
                     From = model.From,
                     Date = model.Date,
                     Hit = model.Hit,
                     Title = model.Title,
                     URL = model.URL
                 }))
             {
                 model.InjuectProcessSuccessMessage();
                 model.InjuectRedrectScript("/ProductMG");
                 model.IsValid = true;
             }
             return View(model);
         }
         [CompanyAuth()]
         public ActionResult DownloadMG(string id, int page = 0)
         {
             var result = PL.ServiceClient.CompanyDownloadServiceClient.GetDownloadFiles(id, 0, page, 15);
             ViewData["Data"] = result;
             return View();
         }
         [CompanyAuth()]
         public int DownloadDeleteItem(string id, string fid)
         {
             return PL.ServiceClient.CompanyDownloadServiceClient.DeleteDownloadFile(id, fid);
         }
         [CompanyAuth()]
         public ActionResult DownloadAddItem(string id)
         {
             DownloadMGModels models = new DownloadMGModels() { Hit = 10 };
             return View(models);
         }
         [HttpPost]
         [CompanyAuth()]
         [ValidateInput(false)]
         public ActionResult DownloadAddItem(string id, DownloadMGModels model)
         {
             if (!ModelState.IsValid)
             {
                 ModelState.AddModelError("", "一些字段输入有误");
                 model.IsValid = false;
                 return View(model);
             }
             if (PL.ServiceClient.CompanyDownloadServiceClient.DownloadAddItem(id,
                 new DownloadDataPack()
                 {
                     Author = model.Author,
                     Hit = model.Hit,
                     Title = model.Title
                 }))
             {
                 model.InjuectProcessSuccessMessage();
                 model.InjuectRedrectScript("/DownloadAddItem");
                 model.IsValid = true;
             }
             return View(model);
         }
         [CompanyAuth()]
         public ActionResult BlogMG(string id)
         {
             var data = PL.ServiceClient.CompanyBlogServiceClient.GetBlogList(id, 0, 5).Select(
                 c => {
                     string nolabel = c.CONTENT.GetStringWithoutHTMLLabel();
                     if (!String.IsNullOrEmpty(nolabel))
                     {
                         c.ABSTRACT = nolabel.Length > 300 ? nolabel.Substring(0, 300) : nolabel;
                     }
                     return c; }).ToList();
             ViewData["Data"] = data;
             return View();
         }
         [CompanyAuth()]
         public ActionResult BlogEditMG(string id, string bid)
         {
             BlogMGModels model = new BlogMGModels();
             int _bid = 0;
             if (Int32.TryParse(bid, out _bid))
             {
                 var data = PL.ServiceClient.CompanyBlogServiceClient.GetBlogArticle(id, _bid);
                 if (data != null)
                 {
                     var item = data[0];
                     model.Author = item.AUTHOR;
                     model.Bid = _bid;
                     model.Content = item.CONTENT;
                     model.Hit = item.HIT;
                     model.MainPhoto = item.URL;
                     model.Title = item.TITLE;
                     model.Date = item.DATE;
                     return View(model);
                 }
             }
             return RedirectToAction("BlogMG");
         }
         [HttpPost]
         [CompanyAuth()]
         [ValidateInput(false)]
         public ActionResult BlogEditMG(string id, BlogMGModels model)
         {
             if (!ModelState.IsValid)
             {
                 ModelState.AddModelError("", "操作失败");
                 model.IsValid = false;
                 return View(model);
             }
             if (PL.ServiceClient.CompanyBlogServiceClient.UpdateBlogArticle(id,
                 new BlogDataPack()
                 {
                     Author = model.Author,
                     Bid = model.Bid,
                     Content = model.Content,
                     Date = model.Date,
                     Hit = model.Hit,
                     MainPhoto = model.MainPhoto,
                     Title = model.Title
                 }))
             {
                 model.InjuectProcessSuccessMessage();
                 model.IsValid = true;
             }
             return View(model);
         }
         [CompanyAuth()]
         public ActionResult BlogAddMG(string id)
         {
             BlogMGModels model = new BlogMGModels() { Hit = 10, Date = DateTime.Now.ToLongDateString() };
             return View(model);
         }
         [HttpPost]
         [CompanyAuth()]
         [ValidateInput(false)]
         public ActionResult BlogAddMG(string id, BlogMGModels model)
         {
             if (!ModelState.IsValid)
             {
                 ModelState.AddModelError("", "操作失败");
                 model.IsValid = false;
                 return View(model);
             }
             if (PL.ServiceClient.CompanyBlogServiceClient.AddBlogArticle(id,
                 new BlogDataPack()
                 {
                     Author = model.Author,
                     Content = model.Content,
                     Date = model.Date,
                     Hit = model.Hit,
                     MainPhoto = model.MainPhoto,
                     Title = model.Title
                 }))
             {
                 model.InjuectProcessSuccessMessage();
                 model.IsValid = true;
             }
             return View(model);
         }
         [CompanyAuth()]
         public int BlogDeleteMG(string id, int bid)
         {
             return PL.ServiceClient.CompanyBlogServiceClient.DeleteBlogArticle(id, bid);
         }

         [CompanyAuth()]
         public ActionResult OnlineMG(string id, int page = 0)
         {
             var data = PL.ServiceClient.CompanyOnlineServiceClient.GetOnlineConsultation(id, page, 5);
             ViewData["Data"] = data;
             return View();
         }
         [CompanyAuth()]
         public int OnlineItemDelete(string id, int mid)
         {
             return PL.ServiceClient.CompanyOnlineServiceClient.DeleteOnlineItem(id, mid);
         }
         [CompanyAuth()]
         public ActionResult OnlineEditMG(string id, int mid)
         {
             var item = PL.ServiceClient.CompanyOnlineServiceClient.GetOnlineConsultationItem(id, mid);
             if (item != null && item.Any())
             {
                 OnlineMGModelas model = new OnlineMGModelas();
                 model.Author = item[0].AUTHOR;
                 model.Content = item[0].CONTENT;
                 model.Mid = mid;
                 model.Reply = item[0].EXTFIELD1;
                 model.Respondent = item[0].EXTFIELD2;
                 model.PHONE = item[0].PHONE;
                 return View(model);
             }
             else
             {
                 return RedirectToAction("OnlineMG");
             }

         }
         [CompanyAuth()]
         [HttpPost]
         public ActionResult OnlineEditMG(string id, OnlineMGModelas model)
         {
             if (!ModelState.IsValid)
             {
                 ModelState.AddModelError("", "操作失败");
                 model.IsValid = false;
                 return View(model);
             }
             if (PL.ServiceClient.CompanyOnlineServiceClient.EditOnlineConsultaion(id,
                 new OnlineDataPack()
                 {
                     Author = model.Author,
                     Content = model.Content,
                     Mid = model.Mid,
                     PHONE = model.PHONE,
                     Reply = model.Reply,
                     Respondent = model.Respondent
                 }))
             {
                 model.InjuectProcessSuccessMessage();
                 model.IsValid = true;
             }
             return View(model);
         }

         [CompanyAuth()]
         public ActionResult BusinessMG(string id,int type = -1,int subject = -1)
         {
             var data = PL.ServiceClient.CompanyBusinessServiceClient.GetBusinessList(id, 0, 10, type, subject);
             ViewData["Data"] = data;
             return View();
         }
         [CompanyAuth()]
         public int BusinessItemDelete(string id, int bid)
         {
             return PL.ServiceClient.CompanyBusinessServiceClient.BusinessItemDelete(id, bid);
         }
         [CompanyAuth()]
         public ActionResult BusinessEditMG(string id, int bid)
         {
             BusinessMGModelas model = new BusinessMGModelas();
             var item = PL.ServiceClient.CompanyBusinessServiceClient.GetBusinessDetail(id, bid);
             if(item == null)
             {
                return RedirectToAction("BusinessMG");
             }
             model.Bid = bid;
             model.Content = item[0].CONTENT;
             model.Title = item[0].TITLE;
             model.Type = Int32.Parse(item[0].TYPE);
             return View(model);
         }
         [HttpPost]
         [CompanyAuth()]
         [ValidateInput(false)]
         public ActionResult BusinessEditMG(string id, BusinessMGModelas model)
         {
             if (!ModelState.IsValid)
             {
                 ModelState.AddModelError("", "操作失败");
                 model.IsValid = false;
                 return View(model);
             }
             if (PL.ServiceClient.CompanyBusinessServiceClient.EditBusinessItem(id, new BusinessDataPack() { 
                Content = model.Content,
                Title = model.Title,
                Bid = model.Bid
             }))
             {
                 model.InjuectProcessSuccessMessage();
                 model.IsValid = true;
             }
             return View(model);
         }

         [CompanyAuth()]
         public ActionResult BusinessAddItem(string id)
         {
             BusinessMGModelas model = new BusinessMGModelas();
             return View(model);
         }
         [CompanyAuth()]
         [HttpPost]
         [ValidateInput(false)]
         public ActionResult BusinessAddItem(string id, BusinessMGModelas model)
         {
             if (!ModelState.IsValid)
             {
                 ModelState.AddModelError("", "操作失败");
                 model.IsValid = false;
                 return View(model);
             }
             if(PL.ServiceClient.CompanyBusinessServiceClient.AddBusinessItem(id,
                 new BusinessDataPack()
                 {
                     Content = model.Content,
                     Title = model.Title,
                     Type = 1
                 }) == 1)
             {
                 model.InjuectProcessSuccessMessage();
                 model.IsValid = true;
             }
             return View(model);
         }
        /*******************/
         [VoidLink]
         public string Upload(string id)
         {
             var files = System.Web.HttpContext.Current.Request.Files;
             if (files.Count > 0)
             {
                 var uploadName = files.Keys[0];
                 var item = PL.ServiceClient.ServiceProviderServiceClient.UploadFiles(
                     new List<UploadFileDataPack>() {
                    new UploadFileDataPack(){
                        BasePath=String.Format(Empires.CRL.Tools.Utils.ReadAppSetting("CustomerImage"),id),
                        TypeFilter = new List<FileType>(){ FileType.All},
                        UploadName =uploadName,
                        CopyMode= CopyMode.rename
                    }
                }, files);
                 if (!String.IsNullOrEmpty(item[uploadName]))
                 {
                     return "{'err':'',msg:'" + item[uploadName] + "'}";
                 }
             }
             return "{'err':'不存在任何上次文件',msg:''}"; ;
         }
    }
}